package com.gouldzd.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.gouldzd.dao.MemberDao;
import com.gouldzd.dao.OrderDao;
import com.gouldzd.service.ReportService;
import com.gouldzd.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
/*
 * @Author zhangdan
 * @Description //TODO 运营数据统计服务
 * @Date 11:05 2020/5/12
 * @Param
 * @return
 **/
@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {

    @Autowired
    private MemberDao memberDao;

    @Autowired
    private OrderDao orderDao;


    //查询运营数据
    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        Map<String,Object> result = new HashMap<>();

        //当前日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //获得当前周,星期一的日期
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获得当前月第一天的日期
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());

        //本日新增会员数
        Integer todayNewMember = memberDao.findMemberCountByDate(today);
        //总会员数
        Integer totalMember = memberDao.findMemberTotalCount();
        //本周新增会员数
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(thisWeekMonday);
        //本月新增会员数
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(firstDay4ThisMonth);

        //今日预约数
        Integer todayOrderNumber = orderDao.findOrderCountByDate(today);
        //本周预约数
        Integer thisWeekOrderNumber = orderDao.findOrderCountAfterDate(thisWeekMonday);
        //本月预约数
        Integer thisMonthOrderNumber = orderDao.findOrderCountAfterDate(firstDay4ThisMonth);

        //今日到诊数
        Integer todayVisitsNumber = orderDao.findVisitsCountByDate(today);
        //本周到诊数
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountAfterDate(thisWeekMonday);
        //本月到诊数
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountAfterDate(firstDay4ThisMonth);

        //热门套餐查询
        List<Map> hotSetmeal = orderDao.findHotSetmeal();

        //日期
        result.put("reportDate",today);
        //本日新增会员数
        result.put("todayNewMember",todayNewMember);
        //总会员数
        result.put("totalMember",totalMember);
        //本周新增会员数
        result.put("thisWeekNewMember",thisWeekNewMember);
        //本月新增会员数
        result.put("thisMonthNewMember",thisMonthNewMember);

        //今日预约数
        result.put("todayOrderNumber",todayOrderNumber);
        //本周预约数
        result.put("thisWeekOrderNumber",thisWeekOrderNumber);
        //本月预约数
        result.put("thisMonthOrderNumber",thisMonthOrderNumber);

        //今日到诊数
        result.put("todayVisitsNumber",todayVisitsNumber);
        //本周到诊数
        result.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        //本周到诊数
        result.put("thisMonthVisitsNumber",thisMonthVisitsNumber);

        //热门套餐
        result.put("hotSetmeal",hotSetmeal);

        return result;
    }
}
